<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		<script src="validate.js"></script>
		<script type="text/javascript">
			const formData={
				email:'123@qq.com',
				username:'w123456',
				tel:'13527456451',
				pwd:'123451231',
				pwd2:'123451231',
				telCode:'099811',
				zipCode:'40000'
			}
			const formRules = [
			  {name: 'email', type: 'required', errmsg: ''},
			  {name: 'email', type: 'email', errmsg: '请输入正确的邮箱'},
			  {name: 'username', type: 'required', errmsg: '请输入用户名'},
			  {name: 'tel', required: true, type: 'phone', errmsg: '请输入正确的手机号'},
			  {name: 'pwd', type: 'required', errmsg: '请输入密码'},
			  {name: 'pwd', type: 'lengthRange',max: 16, errmsg: '密码须是6-16位字符'},
			  {name: 'pwd2', type: 'equals', eqName: 'pwd', required: true, errmsg: '两次输入密码不一致'},
			  {name: 'telCode',required: true, errmsg: '请输入验证码'},
			  {name: 'telCode',type: 'inviteCode', errmsg: '请输入正确的验证码格式'},
			  {name: 'telCode', type: 'lengthRange', min: 6, max: 6, errmsg: '验证码必须是6位字符'},
			  {name: 'zipCode',type: 'zipCode', errmsg: '请输入正确的zipCode'},
			]
			let validate = new Validate(formData,formRules)
			// 自定义校验规则
			validate.addRule('zipCode',(val,msg)=>{
				var reg = /^[0-9]{6}$/;
				if(!reg.test(val)){
					return msg
				}
			})
			// 验证检测
			let result = validate.check()
			if(!result.isOk){
				console.log(result.msg)
			}
		</script>
	</body>
</html>
